<?php

require_once('declarations.php');
require_once('../models/authorization.php');

if($_REQUEST['do'] == "addCategory"){
	$category_controller->addCategory($_REQUEST['category']);
}
if($_REQUEST['do'] == "deleteCategory"){
	$category_controller->deleteCategory($_REQUEST['id']);
}
if($_REQUEST['do'] == "editCategory"){
	$category_controller->editCategory($_REQUEST['id'], $_REQUEST['name']);
}
if($_REQUEST['do'] == "getCategoryName"){
	
	$categoryName = $category_controller->getCategoryName($_REQUEST['id']);
	
	if(!empty($categoryName))
		echo $categoryName;
	else
		echo "Category Does Not Exist!";
}

if($_REQUEST['do'] != "getCategoryName"){
	$smarty->assign("loggedIn", $session->checkLogin());
	$smarty->assign("categories", $category_controller->getAllCategories());
	$smarty->assign("numberOfCategories", Category::getNumberOfCategories());
	$smarty->display('manageCategories.tpl');
}

?>
